import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shop/tools/screenAdapter.dart';

import '../controllers/cart_controller.dart';
import 'cart_item_num_view.dart';

class CartItemView extends GetView {
  final CartController controller = Get.find();
  final Map cartItem;

  CartItemView(this.cartItem, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(
            width: ScreenAdapter.height(2),
            color: Colors.black38,
          ),
        ),
      ),
      padding: EdgeInsets.all(ScreenAdapter.height(20)),
      child: Row(
        children: [
          SizedBox(
            width: ScreenAdapter.width(100),
            child: Checkbox(
              activeColor: Colors.red,
              value: cartItem['checked'],
              onChanged: (value) {
                controller.selectCartShop(cartItem);
              },
            ),
          ),
          Container(
            margin: EdgeInsets.only(right: ScreenAdapter.width(20)),
            width: ScreenAdapter.width(260),
            padding: EdgeInsets.all(ScreenAdapter.height(24)),
            child: Image.network("${cartItem['pic']}", fit: BoxFit.fitHeight),
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '${cartItem['title']}',
                  style: TextStyle(
                    fontSize: ScreenAdapter.fontSize(36),
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(height: ScreenAdapter.height(20)),
                Row(
                  children: [Chip(label: Text('${cartItem['selectedAttr']}'))],
                ),
                SizedBox(height: ScreenAdapter.height(20)),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '￥${cartItem['price'] * cartItem['count']}',
                      style: TextStyle(
                        fontSize: ScreenAdapter.fontSize(38),
                        color: Colors.red,
                      ),
                    ),
                    CartItemNumView(cartItem),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
